package com.yuniarti.konsultasikesehatan;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.TextView;

public class DetailInfoActivity extends Activity {

	String id;
    TextView judul;
    TextView detail;
    TextView konten;
 
    DataParser jParser = new DataParser();
    private static String url_detail_informasi = "http://konsultasi-yakes.web.id/JSON/detail-artikel.php";
    //private static String url_detail_informasi = "http://10.0.2.2/adminweb/JSON/detail-artikel.php";
    
    private static final String AR_ARTIKEL = "artikel";
    private static final String AR_ID = "id";
    private static final String AR_JUDUL = "judul";
    private static final String AR_DETAIL = "tanggal";
    private static final String AR_WAKTU = "waktu";
    private static final String AR_KONTEN = "content";
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_detail_info);
		
		Intent i = getIntent();
        id = i.getStringExtra(AR_ID);
 
        new GetArtikel().execute();
 
    }

    class GetArtikel extends AsyncTask<String, String, String> {

        protected String doInBackground(String... params) {
 
            runOnUiThread(new Runnable() {
                public void run() {
      
                  //  int success;
                    try {
       
                        List<NameValuePair> params = new ArrayList<NameValuePair>();
                        params.add(new BasicNameValuePair("kode", id));
 
                        JSONObject json = jParser.makeHttpRequest(url_detail_informasi, "GET", params);
 
                            JSONArray artikelObj = json.getJSONArray(AR_ARTIKEL); 
 
                            JSONObject product = artikelObj.getJSONObject(0);
 
                            judul= (TextView) findViewById(R.id.judul);
                            detail= (TextView) findViewById(R.id.detail);
                            konten = (TextView) findViewById(R.id.isi);

                            judul.setText(product.getString(AR_JUDUL));
                            detail.setText(product.getString(AR_DETAIL)+" - "+product.getString(AR_WAKTU));
                            konten.setText(product.getString(AR_KONTEN));
            
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            });
 
            return null;
        }
    }
}
